count frequency of each word in a string